package com.zx.cloud.controller;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.Shift;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.common.filter.IgnoreAuth;
import com.zx.cloud.controller.client.LoanClient;
import com.zx.cloud.domain.Dict;
import com.zx.cloud.domain.Edition;
import com.zx.cloud.domain.LoanOrder;
import com.zx.cloud.domain.RepayOrder;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.util.Page;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 * @ClassName: LoanController
 * @Description: 
 * @author: likun
 * @date: 2017年11月1日 下午6:57:00
 */
@RestController
@RequestMapping(value = ApiVersion.API_V1_PREFIX+"/loan", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class LoanController {
	@Autowired
    private LoanClient loanClient;
	
	@RequestLogging
	@ApiOperation(value = "获取利率", notes = "获取利率")
	@RequestMapping(value = "/getDitRate", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<List<Dict>> getDitRate(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		
		return  loanClient.getDitRate();
	}
	@IgnoreAuth
	@RequestLogging
	@ApiOperation(value = "ios审核", notes = "ios审核")
	@RequestMapping(value = "/getIosCheck", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<List<Dict>> getIosCheck(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		
		return loanClient.getIosCheck();
	}
	@RequestLogging
	@ApiOperation(value = "借款管理-创建借款订单", notes = "借款管理-创建借款订单")
	@RequestMapping(value = "/createLoanOrder", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> createLoanOrder(@CurrentUserId Long userId,@RequestBody  LoanOrder loanOrder) throws NoSuchAlgorithmException, InvalidKeySpecException{
		loanOrder.setClientId(userId);
		return loanClient.createLoanOrder(loanOrder);
	}
	@RequestLogging
	@ApiOperation(value = "我的借款记录", notes = "我的借款记录")
	@RequestMapping(value = "/getMyLoanOrderList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<LoanOrder>> getMyLoanOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		loanOrder.setClientId(userId);
		return loanClient.getMyLoanOrderList(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "借款管理-借款订单列表—查看详情", notes = "借款管理-借款订单列表—查看详情")
	@RequestMapping(value = "/getLoanOrderDetail", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<LoanOrder> getLoanOrderDetail(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody LoanOrder loanOrder){
		
		return loanClient.getLoanOrderDetail(loanOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "贷后管理-还款订单列表-查看详情", notes = "贷后管理-还款订单列表-查看详情")
	@RequestMapping(value = "/getRepayOrderDetail", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<RepayOrder> getRepayOrderDetail(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		
		return loanClient.getRepayOrderDetail(repayOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "获取app版本", notes = "获取app版本")
	@RequestMapping(value = "/getAppVersion", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<List<Edition>> getAppVersion(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody Edition edition){
		
		return loanClient.getAppVersion(edition);
	}
	
	@RequestLogging
	@ApiOperation(value = "我的还款记录", notes = "我的还款记录")
	@RequestMapping(value = "/getMyRepayOrderList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<RepayOrder>> getMyRepayOrderList(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		repayOrder.setClientId(userId);
		return loanClient.getMyRepayOrderList(repayOrder);
	}
	
	@RequestLogging
	@ApiOperation(value = "立即还款", notes = "立即还款")
	@RequestMapping(value = "/repayment", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> repayment(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody RepayOrder repayOrder){
		repayOrder.setClientId(userId);
		return  loanClient.repayment(repayOrder);
	}
}
